/**
 * @file common
 * @author: vscode
 * @Date: 2018-10-23 22:37:16
 * @Last Modified by: yejiang1015
 * @Last Modified time: 2018-12-08 17:03:02
 */

'use strict';

const setRes = require('../utils/setRes');
const axios = require('../axios');

class Common {
    static getMethods(req, res) {
        const url = req._parsedUrl.pathname;
        const query = req.query;
        axios.get(url, {
            params: query
        }).then(response => {
            setRes(res, response.data.errno, response.data.data, response.data.errmsg);
        }).catch(error => {
            setRes(res, 500, null, error.message);
        });
    }

    static postMethods(req, res) {
        const url = req._parsedUrl.pathname;
        const body = req.body;
        axios.post(url, body).then(response => {
            setRes(res, response.data.errno, response.data.data, response.data.errmsg);
        }).catch(error => {
            setRes(res, 500, null, error.message);
        });
    }
}

module.exports = Common;
